<template>
	<view class="page-doubleDan-myPrize">
		
		<view class="top-bar">
			<view class="personal-info">
				您好，尊敬的{{ phone }}
			</view>
		</view>
		
		<view class="back-page" @click="onHandleBackPage">
			返回抽奖页面
		</view>
		
		<view class="prize-list" v-if="list && list.length !== 0">
			<!-- <view class="prize-item">
				<view class="item-left">
					<view class="left-value">
						50
						<text>元</text>
					</view>
					<view class="left-name">
						天猫超市卡
					</view>
				</view>
				
				<view class="item-line"></view>
				
				<view class="item-right">
					<view class="right-value">
						<view class="value-in">
							兑换码：123456789123456789123456789123456789123456789
						</view>
						<text class="copy" @click="onHandleCopy">复制</text>
					</view>
					<view class="right-date">
						请在2020-12-31日前完成兑换
					</view>
				</view>
			</view>
			
			<view class="prize-item">
				<view class="item-left">
					<view class="left-value">
						10
						<text>元</text>
					</view>
				</view>
				
				<view class="item-line"></view>
				
				<view class="item-right">
					<view class="right-value">
						推广优惠券
					</view>
					<view class="right-date">
						有效期2020-12-05
					</view>
				</view>
			</view> -->
			
			<block v-for="(item, index) in list" :key="index">
				<block v-if="item.prizeType === 3">
					<view class="prize-item">
						<view class="item-left">
							<view class="left-value">
								{{ item.prizePrice / 100 }}
								<text>元</text>
							</view>
						</view>
						
						<view class="item-line"></view>
						
						<view class="item-right">
							<view class="right-value">
								{{ item.prizeName || '' }}
							</view>
							<view class="right-date">
								有效期：{{ dateUtil.formatTime(item.endTime) }}
							</view>
						</view>
					</view>
				</block>
				
				<block v-else-if="item.prizeType === 2">
					<view class="prize-item">
						<view class="item-left">
							<view class="left-value">
								{{ item.prizePrice / 100 }}
								<text>元</text>
							</view>
							<view class="left-name">
								{{ item.prizeName || '' }}
							</view>
						</view>
						
						<view class="item-line"></view>
						
						<view class="item-right">
							<view class="right-value">
								<view class="value-in">
									兑换码：{{ item.redeemCode || '' }}
								</view>
								<text class="copy" @click="onHandleCopy(item.redeemCode)">复制</text>
							</view>
							<view class="right-date">
								请在{{ dateUtil.formatTime(item.endTime) }}日前完成兑换
							</view>
						</view>
					</view>
				</block>
			</block>
			
			
		</view>
		
		<view class="no-prize" v-else>
			<image src="../../static/empty-prizeList.png" mode="widthFix"></image>
			<view>
				暂无奖品
			</view>
		</view>
		
	</view>
</template>

<script>
	import { getUserInfo, hidePhoneCenter } from '@/utils/index.js';
	import dateUtil from '@/utils/date.js';
	
	
	export default {
		data() {
			return {
				dateUtil: dateUtil,
				list: [],	// 奖品列表
				phone: '',
			};
		},
		onLoad() {
			
			const userInfo = getUserInfo() || {};
			this.phone = hidePhoneCenter(userInfo.phone);
			
			uni.showLoading({
				title: '加载中...',
			})
			
			// 获取奖品列表
			this.$request('/app/activity/doubleDan/getAwardDetails', {
				success: res => {
					uni.hideLoading();
					const data = res.body || [];
					this.list = data;
					// this.list = data.slice(0, 50);
				},
			});
			
		},
		methods: {
			
			// 返回上一页
			onHandleBackPage() {
				uni.navigateBack({})
			},
			
			// 复制功能
			onHandleCopy(data) {
				uni.setClipboardData({
					data: data,
					success: () => {},
					fail: () => {},
				})
			},
			
		},
	}
</script>

<style lang="scss">
	
	@import '@/common/styles/mixin/utils.scss';
	
	.page-doubleDan-myPrize {
		width: 100vw;
		min-height: 100vh;
		background: #F77845;
		padding: 30rpx;
		
		
		.top-bar {
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-bottom: 40rpx;
			
			.personal-info {
				color: #FFFFFF;
				font-size: 28rpx;
			}
		}
		
		.back-page {
			position: fixed;
			top: 20rpx;
			right: 0;
			z-index: 100;
			background: rgba(255, 255, 255, .85);;
			color: #333333;
			font-size: 26rpx;
			padding: 10rpx 20rpx;
			border-radius: 100rpx 0 0 100rpx;
		}
		
		.prize-list {
			.prize-item {
				position: relative;
				display: flex;
				align-items: center;
				color: #F8380A;
				background: #FFF;
				border-radius: 10rpx;
				padding: 22rpx 0;
				margin-bottom: 20rpx;
				font-size: 26rpx;
				
				&::before,
				&::after {
					content: '';
					position: absolute;
					top: 50%;
					width: 30rpx;
					height: 30rpx;
					background: #F77845;
					border-radius: 100%;
				}
				
				&::before {
					left: 0;
					transform: translate(-50%, -50%);
				}
				
				&::after {
					right: 0;
					transform: translate(50%, -50%);
				}
				
				.item-line {
					height: 120rpx;
					border-left: 4rpx dotted #FB888B;
				}
				
				.item-left {
					flex: none;
					display: flex;
					flex-direction: column;
					align-items: center;
					justify-content: center;
					width: 210rpx;
					.left-value {
						font-size: 78rpx;
						line-height: 1;
						font-weight: bold;
						
						& > text {
							font-size: 24rpx;
							font-weight: normal;
						}
					}
					
					.left-name {
						font-size: 24rpx;
						margin-top: 6rpx;
						font-weight: 600;
					}
				}
				
				.item-right {
					flex: 1;
					overflow: hidden;
					margin-left: 30rpx;
					
					.right-value {
						display: flex;
						align-items: center;
						
						.value-in {
							flex: 1;
							word-break: break-all;
							word-wrap: break-word;
							@include ellipsis(2);
							font-size: 22rpx;
						}
						
						.copy {
							flex: none;
							margin: 0 30rpx 0 25rpx;
							text-decoration: underline;
						}
					}
					
					.right-date {
						margin-top: 26rpx;
					}
				}
			}
		}
	
		.no-prize {
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: space-between;
			color: #FFF;
			font-size: 28rpx;
			margin-top: 300rpx;
			opacity: 0.8;
			
			& > image {
				width: 177rpx;
				margin-bottom: 20rpx;
			}
		}
		
	}
</style>
